package sctu.edu.java.year2016.team01.chenhong.day20160604.chapter11_3;

import java.util.Scanner;

/**
 * Created by Administrator on 2016/6/4.
 * Computer类，该类中有一个计算两个数的最大公约数的方法。
 */
public class Computer {


    private static int CommonDivisor(int m, int n) throws MyException {


        if (m < 0 || n < 0) {
            throw new MyException(m, n);

        } else {
            System.out.println(m + "和" + n + "最大公约数为：");
            while (m % n != 0) {


                int temp = m % n;

                m = n;

                n = temp;

            }

            System.out.println(n);


            return n;

        }

    }


    public static void main(String[] args) {

        System.out.println("请输入两个数：");

        Scanner scan = new Scanner(System.in);

        int m = scan.nextInt();
        int n = scan.nextInt();




        try {
            CommonDivisor(m, n);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


}



